//
//  WHContactsDetailTableView.m
//  AddressBook
//
//  Created by  on 2020/7/28.
//  Copyright © 2020 wh. All rights reserved.
//

#import "WHContactsDetailTableView.h"
#import "MacroDefinition.h"
#import "Masonry.h"
#import "WHContactsDetailCell.h"
#import "WHSingleton.h"
#import "UIImageTool.h"

static NSString *detailCellId = @"detailCellId";

@interface WHContactsDetailTableView() <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSArray<NSString *> *titleArr;
@property (nonatomic, strong) NSArray<NSString *> *contentArr;

@end

@implementation WHContactsDetailTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.titleArr = @[@"号码",@"地址"];
        self.delegate = self;
        self.dataSource = self;
        self.tableFooterView = [[UIView alloc] init];
    }
    return self;
}

- (void)setContentWithArr:(NSArray<NSString *>*)contentArr
{
    self.contentArr = contentArr;
}

#pragma mark - tableView delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WHContactsDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:detailCellId];
    if (!cell) {
        cell = [[WHContactsDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:detailCellId];
    }
    [cell setDetailCellDataWithTitle:self.titleArr[indexPath.row] content:self.contentArr[indexPath.row+1]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    if (self.detailTableDelegate && [self.detailTableDelegate performSelector:@selector(detailTableGetScrollContentOffsetY:)]) {
        [self.detailTableDelegate detailTableGetScrollContentOffsetY:offsetY];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (self.detailTableDelegate && [self.detailTableDelegate performSelector:@selector(detailTableStopScrollAction)]) {
        [self.detailTableDelegate detailTableStopScrollAction];
    }
}

#pragma mark - 懒加载
- (NSArray<NSString *> *)titleArr
{
    if (!_titleArr) {
        _titleArr = [[NSArray alloc] init];
    }
    return _titleArr;
}
- (NSArray<NSString *> *)contentArr
{
    if (!_contentArr) {
        _contentArr = [[NSArray alloc] init];
    }
    return _contentArr;
}
@end
